﻿//设计模式 - 观察者模式
//目的：让下面的对象一致的行动


var teacher = new Teacher();

teacher.Add(new Action1());
teacher.Add(new Action2());

teacher.Command();


Console.ReadKey();







interface IAction
{
    void Do();
}

class Action1 : IAction
{
    public void Do() => Console.WriteLine("Action1 做了行为");
}

class Action2 : IAction
{
    public void Do() => Console.WriteLine("Action2 做了行为");
}














class Teacher
{
    List<IAction> actions = new List<IAction>();

    public void Add(IAction action)
    {
        actions.Add(action);
    }
    public void Remove(IAction action)
    {
        actions.Remove(action);
    }

    public void Command()
    {
        actions.ForEach(action => action.Do());
    }
}